<template>
  <el-container class="container">
    <!-- 头部导航 -->
    <el-header class="nav-bar">
      <div class="logo">校园失物招领系统</div>
      <div class="nav-items">
        <router-link to="/usehome">首页</router-link>
        <router-link to="/lost">失物信息</router-link>
        <router-link to="/usefound">招领信息</router-link>
        
        <!-- 通知中心 -->
        <div class="notification-center">
          <NotificationCenter />
        </div>

        <!-- 用户下拉菜单 -->
        <el-dropdown v-if="username" trigger="hover">
          <span class="el-dropdown-link">
            我的<el-icon class="el-icon--right"><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="$router.push('/useprofile')">
                <el-icon><User /></el-icon>我的信息
              </el-dropdown-item>
              <el-dropdown-item @click="$router.push('/my-lost')">
                <el-icon><Collection /></el-icon>我的失物
              </el-dropdown-item>
              <el-dropdown-item @click="$router.push('/my-found')">
                <el-icon><Files /></el-icon>我的招领
              </el-dropdown-item>
              <el-dropdown-item divided @click="handleLogout">
                <el-icon><SwitchButton /></el-icon>退出登录
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>

        <router-link v-else to="/login" class="login-link">登录</router-link>
      </div>
    </el-header>

    <!-- 主体内容 -->
    <el-main class="main-content">
      <RouterView></RouterView>
    </el-main>

    <!-- 页脚 -->
    <el-footer class="site-footer">
      <div class="footer-content">
        <!-- 页脚内容保持不变 -->
      </div>
    </el-footer>
  </el-container>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import {
  User,
  Collection,
  Files,
  SwitchButton,
  ArrowDown
} from '@element-plus/icons-vue'
import NotificationCenter from '@/components/NotificationCenter.vue' // 引入通知中心组件

const router = useRouter()
const username = ref('')

onMounted(() => {
  username.value = localStorage.getItem('username') || ''
})

const handleLogout = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('role')
  localStorage.removeItem('username')
  localStorage.removeItem('userId')
  router.push('/login')
  ElMessage.success('已退出登录')
  username.value = ''
}
</script>

<style scoped>
/* 容器布局调整 */
.container {
  min-height: 100vh;
  width: 60vw; /* 宽度加倍 */
  transform-origin: left center;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 头部样式 */
.el-header.nav-bar {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  border-bottom: 2px solid #eee;
  padding: 0 30px;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: #42b983;
}

.nav-items {
  display: flex;
  align-items: center;
  gap: 25px;
}

/* 通知中心容器 */
.notification-center {
  position: relative;
  margin-right: 10px;
}

.container {
  min-height: 100vh;
  width: 60vw; /* 宽度加倍 */
  transform-origin: left center;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* 头部样式 */
.el-header.nav-bar {
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  border-bottom: 2px solid #eee;
  padding: 0 30px;
}

.logo {
  font-size: 20px;
  font-weight: bold;
  color: #42b983;
}

.nav-items {
  display: flex;
  align-items: center;
  gap: 40px;
}

.el-main.main-content {
  flex: 1;
  width: 100%;
  padding: 20px 0; /* 移除横向padding */
  margin-top: 60px;
  min-height: calc(100vh - 120px);
}
.content-wrapper {
  width: 100%;
  max-width: 1800px; /* 与页脚统一 */
  margin: 0 auto;
  padding: 0 40px;
  box-sizing: border-box;
}
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
/* 页脚样式 */
.el-footer.site-footer {
  height: auto;
  background: #f8f9fa;
  border-top: 1px solid #eee;
  padding: 40px 20px;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 30px;
}

.footer-section {
  text-align: center;
}

.footer-section h4 {
  color: #42b983;
  margin-bottom: 15px;
  font-size: 16px;
}

.footer-section p {
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

/* 其他原有样式保留 */
.el-dropdown-link {
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
}

.login-link {
  color: #666;
  text-decoration: none;
}

.el-icon {
  vertical-align: middle;
  margin-right: 5px;
}

@media (max-width: 1600px) {
  .content-wrapper {
    max-width: 1400px;
    padding: 0 30px;
  }
}

@media (max-width: 1200px) {
  .content-wrapper {
    padding: 0 20px;
  }
  .nav-items {
    gap: 25px;
  }
}

</style>